package model
{	
	import flash.utils.Dictionary;
	
	import mx.core.ByteArrayAsset;
	
	public class Database
	{
	   	private var _clothes:Array = new Array();
	   	private var _outfits:Array = new Array();
	   	
	    // Public methods
	    
	    [Embed(source="database",mimeType="application/octet-stream")]
		private static var db:Class;

		public function Database() {
			populateEmbeddedImagesDictionary();
			var byteArray:Object = new db() as ByteArrayAsset;
			var text:String = byteArray.readUTFBytes(byteArray.length);
			var items:Array = text.split('\n');
			
			for(var i:Number=0;i<items.length;i++){
				var info:Array = items[i].split(':')
				if (info[0] == "cloth") {
					this.addCloth(new Cloth(info[1], info[2], info[3], this));
				}
			}
		}
		
		public function get clothes():Array { return _clothes; }
		public function get outfits():Array { return _outfits; }

		public function addCloth(c:Cloth):void {
			_clothes.push(c);
		}
		
		public function addOutfit(o:Outfit):void {
			_outfits.push(o);
		}
		
		public function findClothInDatabase(s:String):Cloth {
			for(var i:Number=0;i<_clothes.length;i++){
				if (_clothes[i].source == s) {
					return _clothes[i];
				}
			}
			return null;
		}
		
		[Embed(source="assets/clothes/pants/1.jpg")] private var pants_1:Class;
		[Embed(source="assets/clothes/pants/2.jpg")] private var pants_2:Class;
		[Embed(source="assets/clothes/pants/3.jpg")] private var pants_3:Class;
		[Embed(source="assets/clothes/pants/4.jpg")] private var pants_4:Class;
		[Embed(source="assets/clothes/pants/5.jpg")] private var pants_5:Class;
		[Embed(source="assets/clothes/pants/6.jpg")] private var pants_6:Class;
		[Embed(source="assets/clothes/pants/7.jpg")] private var pants_7:Class;
		[Embed(source="assets/clothes/pants/8.jpg")] private var pants_8:Class;
		[Embed(source="assets/clothes/pants/9.jpg")] private var pants_9:Class;
		[Embed(source="assets/clothes/pants/10.jpg")] private var pants_10:Class;
		
		[Embed(source="assets/clothes/belt/1.jpg")] private var belt_1:Class;
		[Embed(source="assets/clothes/belt/2.jpg")] private var belt_2:Class;
		[Embed(source="assets/clothes/belt/3.jpg")] private var belt_3:Class;
		[Embed(source="assets/clothes/belt/4.jpg")] private var belt_4:Class;
		[Embed(source="assets/clothes/belt/5.jpg")] private var belt_5:Class;
		[Embed(source="assets/clothes/belt/6.jpg")] private var belt_6:Class;
		[Embed(source="assets/clothes/belt/7.jpg")] private var belt_7:Class;
		[Embed(source="assets/clothes/belt/8.jpg")] private var belt_8:Class;
		[Embed(source="assets/clothes/belt/9.jpg")] private var belt_9:Class;
		[Embed(source="assets/clothes/belt/10.jpg")] private var belt_10:Class;
		[Embed(source="assets/clothes/belt/11.jpg")] private var belt_11:Class;
		[Embed(source="assets/clothes/belt/12.jpg")] private var belt_12:Class;
		[Embed(source="assets/clothes/belt/13.jpg")] private var belt_13:Class;
		[Embed(source="assets/clothes/belt/14.jpg")] private var belt_14:Class;
		
		[Embed(source="assets/clothes/hat/1.jpg")] private var hat_1:Class;
		[Embed(source="assets/clothes/hat/2.jpg")] private var hat_2:Class;
		[Embed(source="assets/clothes/hat/3.jpg")] private var hat_3:Class;
		[Embed(source="assets/clothes/hat/4.jpg")] private var hat_4:Class;
		[Embed(source="assets/clothes/hat/5.jpg")] private var hat_5:Class;
		[Embed(source="assets/clothes/hat/6.jpg")] private var hat_6:Class;
		[Embed(source="assets/clothes/hat/7.jpg")] private var hat_7:Class;
		[Embed(source="assets/clothes/hat/8.jpg")] private var hat_8:Class;
		[Embed(source="assets/clothes/hat/9.jpg")] private var hat_9:Class;
		[Embed(source="assets/clothes/hat/10.jpg")] private var hat_10:Class;
		[Embed(source="assets/clothes/hat/11.jpg")] private var hat_11:Class;
		[Embed(source="assets/clothes/hat/12.jpg")] private var hat_12:Class;
		[Embed(source="assets/clothes/hat/13.jpg")] private var hat_13:Class;
		[Embed(source="assets/clothes/hat/14.jpg")] private var hat_14:Class;
		
		[Embed(source="assets/clothes/jacket/1.jpg")] private var jacket_1:Class;
		[Embed(source="assets/clothes/jacket/2.jpg")] private var jacket_2:Class;
		[Embed(source="assets/clothes/jacket/3.jpg")] private var jacket_3:Class;
		[Embed(source="assets/clothes/jacket/4.jpg")] private var jacket_4:Class;
		[Embed(source="assets/clothes/jacket/5.jpg")] private var jacket_5:Class;
		[Embed(source="assets/clothes/jacket/6.jpg")] private var jacket_6:Class;
		[Embed(source="assets/clothes/jacket/7.jpg")] private var jacket_7:Class;
		[Embed(source="assets/clothes/jacket/8.jpg")] private var jacket_8:Class;
		[Embed(source="assets/clothes/jacket/9.jpg")] private var jacket_9:Class;
		[Embed(source="assets/clothes/jacket/10.jpg")] private var jacket_10:Class;
		
		[Embed(source="assets/clothes/shirt/1.jpg")] private var shirt_1:Class;
		[Embed(source="assets/clothes/shirt/2.jpg")] private var shirt_2:Class;
		[Embed(source="assets/clothes/shirt/3.jpg")] private var shirt_3:Class;
		[Embed(source="assets/clothes/shirt/4.jpg")] private var shirt_4:Class;
		[Embed(source="assets/clothes/shirt/5.jpg")] private var shirt_5:Class;
		[Embed(source="assets/clothes/shirt/6.jpg")] private var shirt_6:Class;
		[Embed(source="assets/clothes/shirt/7.jpg")] private var shirt_7:Class;
		[Embed(source="assets/clothes/shirt/8.jpg")] private var shirt_8:Class;
		[Embed(source="assets/clothes/shirt/9.jpg")] private var shirt_9:Class;
		[Embed(source="assets/clothes/shirt/10.jpg")] private var shirt_10:Class;
		
		[Embed(source="assets/clothes/shoes/1.jpg")] private var shoes_1:Class;
		[Embed(source="assets/clothes/shoes/2.jpg")] private var shoes_2:Class;
		[Embed(source="assets/clothes/shoes/3.jpg")] private var shoes_3:Class;
		[Embed(source="assets/clothes/shoes/4.jpg")] private var shoes_4:Class;
		[Embed(source="assets/clothes/shoes/5.jpg")] private var shoes_5:Class;
		[Embed(source="assets/clothes/shoes/6.jpg")] private var shoes_6:Class;
		[Embed(source="assets/clothes/shoes/7.jpg")] private var shoes_7:Class;
		[Embed(source="assets/clothes/shoes/8.jpg")] private var shoes_8:Class;
		[Embed(source="assets/clothes/shoes/9.jpg")] private var shoes_9:Class;
		[Embed(source="assets/clothes/shoes/10.jpg")] private var shoes_10:Class;
		[Embed(source="assets/clothes/shoes/11.jpg")] private var shoes_11:Class;
		[Embed(source="assets/clothes/shoes/12.jpg")] private var shoes_12:Class;
		[Embed(source="assets/clothes/shoes/13.jpg")] private var shoes_13:Class;
		[Embed(source="assets/clothes/shoes/14.jpg")] private var shoes_14:Class;
 		
	   	public var embeddedImages:Dictionary = new Dictionary();
	   	
	   	public function populateEmbeddedImagesDictionary():void {
	   		embeddedImages['pants'] = new Dictionary();
	   		embeddedImages['pants']['1'] = pants_1;
	   		embeddedImages['pants']['2'] = pants_2;
	   		embeddedImages['pants']['3'] = pants_3;
	   		embeddedImages['pants']['4'] = pants_4;
	   		embeddedImages['pants']['5'] = pants_5;
	   		embeddedImages['pants']['6'] = pants_6;
	   		embeddedImages['pants']['7'] = pants_7;
	   		embeddedImages['pants']['8'] = pants_8;
	   		embeddedImages['pants']['9'] = pants_9;
	   		embeddedImages['pants']['10'] = pants_10;
	   		
	   		embeddedImages['belt'] = new Dictionary();
	   		embeddedImages['belt']['1'] = belt_1;
	   		embeddedImages['belt']['2'] = belt_2;
	   		embeddedImages['belt']['3'] = belt_3;
	   		embeddedImages['belt']['4'] = belt_4;
	   		embeddedImages['belt']['5'] = belt_5;
	   		embeddedImages['belt']['6'] = belt_6;
	   		embeddedImages['belt']['7'] = belt_7;
	   		embeddedImages['belt']['8'] = belt_8;
	   		embeddedImages['belt']['9'] = belt_9;
	   		embeddedImages['belt']['10'] = belt_10;
	   		embeddedImages['belt']['11'] = belt_11;
	   		embeddedImages['belt']['12'] = belt_12;
	   		embeddedImages['belt']['13'] = belt_13;
	   		embeddedImages['belt']['14'] = belt_14;

	   		embeddedImages['hat'] = new Dictionary();
	   		embeddedImages['hat']['1'] = hat_1;
	   		embeddedImages['hat']['2'] = hat_2;
	   		embeddedImages['hat']['3'] = hat_3;
	   		embeddedImages['hat']['4'] = hat_4;
	   		embeddedImages['hat']['5'] = hat_5;
	   		embeddedImages['hat']['6'] = hat_6;
	   		embeddedImages['hat']['7'] = hat_7;
	   		embeddedImages['hat']['8'] = hat_8;
	   		embeddedImages['hat']['9'] = hat_9;
	   		embeddedImages['hat']['10'] = hat_10;
	   		embeddedImages['hat']['11'] = hat_11;
	   		embeddedImages['hat']['12'] = hat_12;
	   		embeddedImages['hat']['13'] = hat_13;
	   		embeddedImages['hat']['14'] = hat_14;
	   		
	   		embeddedImages['jacket'] = new Dictionary();
	   		embeddedImages['jacket']['1'] = jacket_1;
	   		embeddedImages['jacket']['2'] = jacket_2;
	   		embeddedImages['jacket']['3'] = jacket_3;
	   		embeddedImages['jacket']['4'] = jacket_4;
	   		embeddedImages['jacket']['5'] = jacket_5;
	   		embeddedImages['jacket']['6'] = jacket_6;
	   		embeddedImages['jacket']['7'] = jacket_7;
	   		embeddedImages['jacket']['8'] = jacket_8;
	   		embeddedImages['jacket']['9'] = jacket_9;
	   		embeddedImages['jacket']['10'] = jacket_10;

	   		embeddedImages['shirt'] = new Dictionary();
	   		embeddedImages['shirt']['1'] = shirt_1;
	   		embeddedImages['shirt']['2'] = shirt_2;
	   		embeddedImages['shirt']['3'] = shirt_3;
	   		embeddedImages['shirt']['4'] = shirt_4;
	   		embeddedImages['shirt']['5'] = shirt_5;
	   		embeddedImages['shirt']['6'] = shirt_6;
	   		embeddedImages['shirt']['7'] = shirt_7;
	   		embeddedImages['shirt']['8'] = shirt_8;
	   		embeddedImages['shirt']['9'] = shirt_9;
	   		embeddedImages['shirt']['10'] = shirt_10;
	   		
	   		embeddedImages['shoes'] = new Dictionary();
	   		embeddedImages['shoes']['1'] = shoes_1;
	   		embeddedImages['shoes']['2'] = shoes_2;
	   		embeddedImages['shoes']['3'] = shoes_3;
	   		embeddedImages['shoes']['4'] = shoes_4;	
	   		embeddedImages['shoes']['5'] = shoes_5;	
	   		embeddedImages['shoes']['6'] = shoes_6;	
	   		embeddedImages['shoes']['7'] = shoes_7;	
	   		embeddedImages['shoes']['8'] = shoes_8;	
	   		embeddedImages['shoes']['9'] = shoes_9;	
	   		embeddedImages['shoes']['10'] = shoes_10;
	   		embeddedImages['shoes']['11'] = shoes_11;
	   		embeddedImages['shoes']['12'] = shoes_12;
	   		embeddedImages['shoes']['13'] = shoes_13;
	   		embeddedImages['shoes']['14'] = shoes_14;	   		
	   	}
	}
}